﻿using GraphProcessor;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.LinearMoveBySpecifiedDir, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_LinearMoveBySpecifiedDir : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.LinearMoveBySpecifiedDir;

        public override string name => LevelEditorConst.LinearMoveBySpecifiedDir;
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [InspectorName("移动距离(cm)")] public int moveDis;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.Teleport, "移动方向(向量方向)")]
        public Vector3 dir;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_LinearMoveBySpecifiedDir()
            {
                // tagOrMcid = this.tagOrMcid,
                moveDis = this.moveDis,
                dir = new Int3(this.dir * 100)
            };
            this.tagOrMcid = new EditorLevelServiceTargetSetter(x => rConfig.tagOrMcid = x);
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_LinearMoveBySpecifiedDir rNode)
            {
                this.moveDis = rNode.moveDis;
                this.dir = rNode.dir;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_LinearMoveBySpecifiedDir rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid);
            }
        }
    }
}